import openpyxl
#将爬取的数据存储到excl表格当中
import requests
import re
def getdata () :
    url = 'https://www.weather.com.cn/weather/101070102.shtml'
    r = requests.get(url)
    r.encoding ='utf-8'
    print(r.text)
    city = re.findall('<span class="name">([\u4e00-\u9fa5]*)</span>', r.text)
    weather = re.findall('<span class="weather">([\u4e00-\u9fa5]*)</span>', r.text)
    wd = re.findall('<span class="wd">(.*)</span>',r.text)
    zs = re.findall('<span class="zs">([\u4e00-\u9fa5]*)</span>', r.text)
    z = zip(city,weather,wd,zs)
    lst = []
    for a,b,c,d in z :
        lst.append([a,b,c])
    return lst
result = getdata()

# 创建一个excl文件
xls = openpyxl.Workbook()
# 创建一个sheet
sheet = xls.create_sheet('sheet1')
# 循环数据，放入sheet中
for item in result :
    sheet.append(item)
# 保存文件
xls.save('test.xlsx')